package demo;

import java.util.Scanner;

public class Text43 {
    public static void main(String[] args) {
        /*在唱歌比赛中，统计六名评委打分【1-100】之间的整数选手最后得分：去最高、最低分的
        4个评委的平均值，计算出选手得分*/
        int[] scorearr = getscores();
        for (int i = 0; i < scorearr.length; i++) {
            System.out.println(scorearr[i]);
        }
        int max = getmax(scorearr);
        int min = getmin(scorearr);
        int sum=getsum(scorearr);
        int avg=(sum-max-min)/(scorearr.length-2);
        System.out.println("选手最终得分："+avg);

        //定义新数组存储六名评委的打分
        //得出最大值和最小值
        //求和
        //最终得分=（总分-最大-最小）/4
    }

    public static int getsum(int[] scorearr) {
        int sum = 0;
        for (int i = 0; i < scorearr.length; i++) {
            sum = sum + scorearr[i];
        }
        return sum;
    }

    public static int getmax(int[] scorearr) {
        int max = scorearr[0];
        for (int i = 1; i < scorearr.length; i++) {
            if (scorearr[i] > max) {
                max = scorearr[i];
            }
        }
        return max;

    }

    public static int getmin(int[] scorearr) {
        int min = scorearr[0];
        for (int i = 1; i < scorearr.length; i++) {
            if (scorearr[i] < min) {
                min = scorearr[i];
            }
        }
        return min;
    }
        public static int[] getscores () {
            int[] scores = new int[6];
            Scanner sc = new Scanner(System.in);
            for (int i = 0; i < scores.length; ) {
                System.out.println("请输入评委的打分：");
                int score = sc.nextInt();
                if (score >= 0 && score <= 100) {
                    scores[i] = score;
                    i++;
                } else {
                    System.out.println("当前输入不在范围内，请重新输入，当前值为：" + i);
                }
            }
            return scores;
        }
    }